package zhuyun.code.launcheractivity.view.adapter

import android.util.SparseArray
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

/**
 * @author: Administrator
 * @date: 2021/11/21
 */
class BaseViewHolder(val view: View):RecyclerView.ViewHolder(view) {
    private val views = SparseArray<View>()

    fun <out: View> getView(viewId:Int):out{
        var view = views.get(viewId)
        if(view == null){
            view = itemView.findViewById(viewId)
            views.put(viewId,view)
        }
        return view as out
    }
    fun setText(viewId:Int, value:CharSequence):BaseViewHolder{
        val view = getView<TextView>(viewId)
        view.text = value
        return this
    }



    fun setVisibility(viewId:Int,value:Int){
        val view = getView<View>(viewId)
        view.visibility = value
    }



}